const orderModel = require('../models/orderModel');


module.exports.find = async function(page,searchParams){
    // return await orderModel.find(searchParams);
    // console.log(page)
    let {current,pageSize} = page;
    console.log(current,pageSize)
    // 根据查询条件获取总数
    let total = await orderModel.countDocuments(searchParams);
    // 根据查询条件获取具体数量的数据
    let data = await orderModel.find(searchParams)
                    .limit(pageSize)
                    .skip((current - 1) * pageSize)
                    .sort({ "_id": -1 })
                    .exec();
    return {
        current,pageSize,total,rows:data,
    }
    
}

module.exports.findById = async function(id){
    return await orderModel.findById(id);
}

module.exports.delete = async function(id){
    return await orderModel.deleteOne({_id:id});
}

module.exports.update = async function(order){
    return await orderModel.updateOne({_id:order._id},order);
}
